/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;
import javax.swing.JOptionPane;
import java.util.GregorianCalendar;
import java.text.DateFormat;

/**
 *
 * @author attobra
 */
public class JoyeuxAnniversaire {
    
        public static void main (String[] args){
            
            
            
            DateFormat formatJour = DateFormat.getDateInstance(DateFormat.FULL);
            String dateAnniv = JOptionPane.showInputDialog(null, "Enter votre date d'anniversaire (jj/mm)");
            int indiceSlash = dateAnniv.indexOf('/');
            int jouranniv = Integer.parseInt(dateAnniv.substring(0,indiceSlash));
            int moisAnniv = Integer.parseInt(dateAnniv.substring(indiceSlash+1));
            
            GregorianCalendar dateActuel = new GregorianCalendar();
            GregorianCalendar dateAnniversaire = new java.util.GregorianCalendar(dateActuel.get(GregorianCalendar.YEAR),moisAnniv-1,jouranniv);
            
            int joursRestant = dateAnniversaire.get(GregorianCalendar.DAY_OF_YEAR) - dateActuel.get(GregorianCalendar.DAY_OF_YEAR);
            if(joursRestant == 0)
                JOptionPane.showMessageDialog(null, "Bonne aniversaire");
            else{
                if(dateAnniversaire.before(dateActuel)){
                    GregorianCalendar prochain31Decembre = new java.util.GregorianCalendar(dateActuel.get(GregorianCalendar.YEAR)+1,GregorianCalendar.DECEMBER,31);
                    dateAnniversaire.set(GregorianCalendar.YEAR, dateActuel.get(GregorianCalendar.YEAR)+1);
                    joursRestant = dateAnniversaire.get(GregorianCalendar.DAY_OF_YEAR)+prochain31Decembre.get(GregorianCalendar.DAY_OF_YEAR)-dateActuel.get(GregorianCalendar.DAY_OF_YEAR);  
                }
              
             JOptionPane.showMessageDialog(null, "Votre anniversaire sera célébré dans "+ joursRestant+ " jours c'est à dire le "+ formatJour.format(dateAnniversaire.getTime()) );   
            
                
            }
            
        }
    
}
